package com.example.iceman.stepcounterapp;

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ScrollView;
import android.widget.TextView;

import butterknife.Bind;
import butterknife.ButterKnife;

/**
 * Created by iceman on 16/2/3.
 */
public class LogFragment extends Fragment implements View.OnClickListener {
    @Bind(R.id.textView)
    TextView textView;
    @Bind(R.id.scrollview)
    ScrollView scrollview;

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        View root = inflater.inflate(R.layout.log_view_layout, container, false);
        ButterKnife.bind(this, root);
        textView.setOnClickListener(this);
        return root;
    }

    @Override
    public void onDestroyView() {
        super.onDestroyView();
        ButterKnife.unbind(this);
    }

    public void log(String s) {
        if (textView != null) {
            textView.append(s + "\n");
            scrollview.fullScroll(ScrollView.FOCUS_DOWN);
        }
    }

    public void clear() {
        if (textView != null) {
            textView.setText("");
        }
    }

    @Override
    public void onClick(View v) {
        getFragmentManager().beginTransaction().hide(this).commit();
    }
}
